package com.zhentao.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class KafkaController {
    @Autowired
    private KafkaTemplate<String,String> kafkaTemplate;

    @RequestMapping("/send")
    @Async
    public String send(){
        for (int i = 0; i < 20; i++) {
            kafkaTemplate.send("topic3","要发送的数据"+i);
        }
        return "发送消息";
    }
}
